<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
	<title>js随机输出给定的数</title>
</head>
<body>
<p class="room-num"></p>
<p class="explain"></p>
<p class="room-price"></p>
<p class="prepayment"></p>
<button onclick="changeRoom()">换一间</button>
</body>
</html>
<script type="text/javascript" src="jquery-1.7.2.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
	changeRoom();
})
var str = [
['201','电脑房','280元','480元'],
['302','商务房','200元','400元'],
['301','标间','400元','800元'],
['401','套房','300元','600元'],
];
var num = 0;
function changeRoom(){
	num++;
    if(num > 3){
    $('.change_room').attr('disabled',true);
        alert('不好意思，你已经换了三次房间，不能再换了！！');ex
         return;
     }
    var index = Math.floor(Math.random()*str.length);
    var result = str[index];
    $('.room-num').text(result[1]);
    $('.explain').text(result[2]);
    console.log('result==='+result);
    console.log('result.length==='+result.length);
    $('.top .room_num').text(result);
    str.splice(index,1);
    console.log('str==='+str);
  
}
</script>